package com.zl.controller;

import com.zl.common.Result;
import com.zl.dto.UserDto;
import com.zl.entity.UserEntity;
import com.zl.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
//@CrossOrigin(origins = "http://localhost:8080/")
public class UserController {
    @Resource
    private IUserService userService;

    @GetMapping("/{id}")
    public Result getUser(@PathVariable Integer id){
        UserEntity entity = userService.getById(id);
        return Result.ok(entity);
    }

    @PostMapping("/login")
    public Result login(@RequestBody UserDto userDto, HttpSession session, HttpServletResponse response){
        return userService.login(userDto);
    }

    @PostMapping("/register")
    public Result register(@RequestBody UserDto userDto){
        return userService.register(userDto);
    }

}
